﻿;
// 移动端字体设置
(function (window, document) {
	var FontSize = function(){
		var xhhtml = document.documentElement;                    //获取到html元素
		var xhwidth = xhhtml.clientWidth;                           //网页可见区域宽
		var xhheight = xhhtml.clientHeight;                         //网页可见区域高

		if (xhheight < xhwidth) { xhwidth = xhheight; }
		if (xhwidth > 750) { 
			xhhtml.style.fontSize =  xhwidth / 15 + "px";
		}else{
			xhhtml.style.fontSize = xhwidth / 7.5 + "px";
		}
	}
	// 暴漏方法
	window.FontSize = FontSize;
}(window,document));

// xhLib通用函数库
jQuery.xhLib = {
	// 判断是否为空
	isEmpty: function (v) {
		if (v == null) return true;
		if (v.length == 0) return true;
		var reg = new RegExp("^[ ]+$");
		return reg.test(v)
	},
	// 转整数
	toInt: function (v, d) {
		if (isNaN(parseInt(v))) {
			return d;
		} else {
			return parseInt(v);
		}
	},
	// 生成Guid字符串
	Guid: function () {
		return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
			var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
			return v.toString(16);
		});
	},
	// 获取当前地址
	getPagePath: function () {
		return window.location.pathname + window.location.search;
	},
};

// xhLocal专用函数库
jQuery.xhLocal = {
	// 获得上传文件路径
	getFilePath: function (fileName, prefix, domain) {
		if (!$.xhLib.isEmpty(fileName)) {
			if (fileName.indexOf('http') >= 0) {
				return fileName;
			} else {
				return domain + '/' + prefix + '/' + fileName.substr(0, 4) + '/' + fileName;
			}
		} else {
			return "";
		}
	},
	// 设置Plupload上传控件参数
	setUploadParam: function (up, file, prefix, toOss, ossParamUrl) {
		let pos = file.name.lastIndexOf('.')
		let suffix = file.name.substring(pos);			// 上传文件后缀
		let _objectName;								// 上传文件名称

		if (toOss) {
			let _multipart_params;																		//上传参数
			$.getJSON(ossParamUrl, function (relt) {
				let json = relt.RespBody;
				let expire = parseInt(json.expire);														//过期时间，暂时没用到
				console.log(json);

				_objectName = prefix + '/' + file.id.substr(0, 4) + '/' + file.id + suffix
				_multipart_params = {
					'key': _objectName,
					'policy': json.policy,
					'OSSAccessKeyId': json.accessid,
					'success_action_status': '200',														//让服务端返回200,不然，默认会返回204
					'signature': json.signature,
				};

				console.log(_multipart_params);

				up.setOption({
					'url': json.host,
					'multipart_params': _multipart_params
				});

			});
		} else {
			_objectName = file.id + suffix;
			up.setOption('multipart_params', {
				"pathPrefix": prefix,
				"key": _objectName
			});
		}
	},
	// Ajax结果预处理
	ajaxReltHandle: function(relt) {
		if (relt.RespHead.Code == '0000') {
			return relt.RespBody;
		} else if(relt.RespHead.Code == "1100") {
			// 退出登录
			$.xhToast({
                msg: relt.RespHead.Message,
                url: "/"
            });
			return false;
		} else {
			$.xhToast({
                msg: relt.RespHead.Message
            });
			return false;
		}
	},
	// 获得文件名(suffix默认=.jpg)
	getFileName: function (suffix) {
		// 获得文件夹
		let _d = new Date();
		let _y = _d.getFullYear().toString().substr(-2);
		let _m = ("0" + (_d.getMonth() + 1).toString()).substr(-2);
		let prefix = _y + _m;
		// 返回文件夹名
		$.xhLib.isEmpty(suffix) ? ".jpg" : suffix;
		return prefix + "-" + $.xhLib.Guid() + suffix;
	},
};



// 消息弹窗
jQuery.xhToast = function (obj) {
	$(function(){
		let _msg = obj.msg || "";							// 显示内容
		let _url = obj.url || "";							// 跳转地址，默认为空
		let _target = obj.target || "self";					// 跳转方式（self/top）跳转地址不为空时有效
		let _duration = obj.duration || 2000;				// 显示时间
		let _func = obj.func || function () { };			// 关闭遮罩后执行事件

		if (_msg != "") {
			let _html = `
						<article class="xhtoast">
							<div class="xhtoast_msgbox">` + _msg + `</div>
						</article>
						`;

			$("body").append(_html);

			setTimeout(function () {
				$(".xhtoast").remove();

				_func();

				if (!$.xhLib.isEmpty(_url)) {
					if (_target == "self") {
						window.location.href = _url;
					} else if (_target == "top") {
						top.location.href = _url;
					} else if (_target == "parent") {
						parent.location.href = _url;
					}
				}
			}, _duration);
		} else {

			_func();

			if (!$.xhLib.isEmpty(_url)) {
				if (_target == "self") {
					window.location.href = _url;
				} else if (_target == "top") {
					top.location.href = _url;
				} else if (_target == "parent") {
					parent.location.href = _url;
				}
			}

		}
	})
};

// xhForm表单
(function ($) {
	$.fn.xhForm = function (options) {
		// 验证程序
		verify = {
			// 必填
			required: {
				func: function (e, v) {
					if ($.xhLib.isEmpty(v)) {
						return false;
					} else {
						return true;
					}
				},
				tip: "必填项不能为空"
			},
			// 手机号
			mobile: {
				func:function (e, v) {
					console.log("手机号码验证");
				},
				tip:""
			}
		};

		// 初始化表单
		init = function (e) {
			//if (e.find("select").length > 0) {
			//}
		};

		// 接收参数
		var opts = $.extend({}, $.fn.xhForm.defaults, options);

		// 主程序
		this.each(function () {
			var $this = $(this);

			// 追加验证程序
			$.extend(verify, opts.verify);

			// 内部初始化
			init($this);
			// 注入初始化
			opts.init();

			// 提交表单
			$this.on("click", "[xh_submit]", function () {
				let vRelt = true;

				// 控件验证
				$this.find("[xh_verify]").each(function () {
					let e = $(this);
					let v = e.val();

					let tip = e.closest(".xhform_item").find(".xhform_item_tip");
					let vAry = e.attr("xh_verify").split("|");

					$.each(vAry, function () {
						let myRelt = verify[this].func(e, v);
						if (!myRelt) {
							vRelt = myRelt;
							if (tip.length > 0) {
								tip.html(verify[this].tip);
								tip.show();
							}
							return false;
						} else {
							if (tip.length > 0) {
								tip.hide();
							}
						}
					 });  
				});

				if (vRelt) {
					opts.submit();
				} else {
					return false;
				}
            })
		});
	};

	$.fn.xhForm.defaults = {
		init: function () { },
		verify: {},
		submit: function () { },
	};
})(jQuery);

// xhPicker多级联动（移动端）
(function ($) {
	$.fn.xhPicker = function (options) {
		var opts = $.extend({}, $.fn.xhPicker.defaults, options);
		
		this.each(function () {
			var $this = $(this);

			$this.unbind("click");
			$this.click(function () {
				var scrollTop = $(document).scrollTop();

				// 被选中的对象
				let _Selected = [];

				// 当前操作层级
				let _CurrLevel = 1;

				// 已操作过的层级
				let _MaxLevel = 1;

				// 当前操作的对象
				let _CurrData = opts.data;

				let _SearchHTml = `
					<div class="xhPicker_search">
						<p><input type="text" id="xhPicker_searchKey" placeholder="请输入检索关键词" autocomplete="off" /></p>
						<a href="javascript:void(0)" id="xhPicker_search">检索</a>
					</div>
				`;

				// 选项标题栏
				let _TitleHtml = `<ul class="xhPicker_itemTitle">`;
				let _TitleWidth = parseInt(100 / opts.level);
				for (var i = 1; i <= opts.level; i++) {
					if (i == 1) {
						_TitleHtml += `<li class="currTitle" data-level="` + i + `" style="width:` + _TitleWidth + `%"><label>请选择</label><span></span></li>`
					} else {
						_TitleHtml += `<li data-level="` + i + `" style="width:` + _TitleWidth + `%"><label>请选择</label><span></span></li>`
					}
				}
				_TitleHtml += `</ul>`;

				// 选项列表
				let _ListBox = ``;
				for (var i = 1; i <= opts.level; i++) {
					if (i == 1) {
						_ListBox += `<ul class="xhPicker_list currList" data-level="` + i + `">`;
						for (var j = 0; j < _CurrData.length; j++) {
							_ListBox += `<li data-key="` + _CurrData[j].key + `">` + _CurrData[j].value + `</li>`;
						}
						_ListBox += `</ul>`;
					} else {
						_ListBox += `<ul class="xhPicker_list" data-level="` + i + `"></ul>`;
					}
				}

				$('body').append(
					`
					<section class="xhPicker">
						<div class="xhPicker_main">
							<div class="xhPicker_title">
								<a href="javascript:void(0)"></a>
								<span>` + opts.title + `</span>
								<a href="javascript:void(0)" id="xhPicker_close">×</a>
							</div>
							` + (opts.search ? _SearchHTml : ``) + _TitleHtml + _ListBox + `
						</div>
					</section>
					`
				);

				// 锁死body
				$('body').css({ "position": "fixed", "width": "100vw", "height": "100vh", "overflow": "hidden" });

				// 取消功能
				$("#xhPicker_close").click(function () {
					$(".xhPicker").remove();
					$('body').css({ "position": "static", "height": "auto", "overflow": "auto" });
					$(document).scrollTop(scrollTop);
				});

				// 检索
				$("#xhPicker_search").click(function () {
					var _key = $("#xhPicker_searchKey").val();

					if (_key != "") {
						$(".xhPicker .currList li").each(function () {
							if ($(this).html().indexOf(_key) >= 0) {
								$(this).show();
							} else {
								$(this).hide();
							}
						});
					} else {
						var e = "请填写检索关键词";
						opts.err(e);
					}
				});

				// 选择层级
				$(".xhPicker_itemTitle li").click(function () {
					let thislevel = parseInt($(this).attr("data-level"));
					if (_MaxLevel >= thislevel) {
						_CurrLevel = thislevel;
						_CurrData = opts.data;
						for (var i = 1; i < _CurrLevel; i++) {
							let thisSelect = _Selected[i - 1];
							$.each(_CurrData, function () {
								if (this.key == thisSelect.key) {
									_CurrData = this.children;
									return false;
								}
							});
						}

						$(".xhPicker_list").removeClass("currList");
						$(".xhPicker_list[data-level=" + _CurrLevel + "]").addClass("currList");

						$(".xhPicker_itemTitle li").removeClass("currTitle");
						$(this).addClass("currTitle");
					}
				});

				// 选择事件
				$(".xhPicker_list").on("click", "li", function () {
					var i = $(this).index();

					_Selected.splice(_CurrLevel - 1, _Selected.length - _CurrLevel + 1);

					var _currSelect = {
						key: $(this).attr("data-key"),
						value: $(this).html()
					}
					_Selected.push(_currSelect);

					if (_CurrLevel < opts.level) {
						_CurrData = _CurrData[i].children;
						// 清空搜索内容
						$("#xhPicker_searchKey").val("");
						$(this).closest(".xhPicker_list").find("li").show();
						// 隐藏本层选项
						$(this).closest(".xhPicker_list").removeClass("currList");
						// 清空后续层级的选项
						$(this).closest(".xhPicker_list").nextAll().find("li").remove();
						// 下层选项追加
						for (var i = 0; i < _CurrData.length; i++) {
							var _item = `<li data-key="` + _CurrData[i].key + `">` + _CurrData[i].value + `</li>`;
							$(this).closest(".xhPicker_list").next().append(_item);
						}
						$(this).closest(".xhPicker_list").next().addClass("currList");
						// 标题栏变更
						$(".xhPicker_itemTitle li[data-level=" + _CurrLevel + "]").removeClass("currTitle");
						$(".xhPicker_itemTitle li[data-level=" + _CurrLevel + "] label").html($(this).html());
						$(".xhPicker_itemTitle li[data-level=" + _CurrLevel + "]").next().addClass("currTitle");
						$(".xhPicker_itemTitle li[data-level=" + _CurrLevel + "]").nextAll().find("label").html("请选择");
						// 处理完成层级+1
						_CurrLevel += 1;

						if (_CurrLevel > _MaxLevel) {
							_MaxLevel = _CurrLevel;
						}
					} else {
						$(".xhPicker").remove();
						$('body').css({ "position": "static", "height": "auto", "overflow": "auto" });
						opts.complate(_Selected);
						$(document).scrollTop(scrollTop);
					}
				});
			});
		});
	};

	$.fn.xhPicker.defaults = {
		title: '选择器',
		data: [{ key: 1, value: "选项1", children: [{ key: 11, value: "子项1" }, {key:12, value: "子项2"}] }, { key: 2, value: "选项2" }],
		level: 2,
		search: false,
		complate: function (i) { },
		err: function (e) { }
	};
})(jQuery);

// xhLinkDrop多级联动下拉菜单（电脑端）
(function ($) {
	$.fn.xhLinkDrop = function (options) {
		var opts = $.extend({}, $.fn.xhLinkDrop.defaults, options);
		
		this.each(function () {
			var $this = $(this);

			let _Selected = opts.selected;

			// 当前操作的对象
			let _InitData = opts.data;

			let _html = `<div class="xhLinkDrop">`;
			// 输出控件
			for (var i = 1; i <= opts.level; i++) {
				if (_Selected.length >= i) {
					let selectKey = _Selected[i - 1].key;
					let selectValue = _Selected[i - 1].value;

					_html += `
						<div class="xhLinkDrop_item" date-level="` + i + `">
							<div class="xhSelect">
								<p class="xhSelect_relt">
									<span data-key="` + selectKey + `">` + selectValue + `</span>
									<i class="iconfont icon-row-bottom2"></i>
								</p>
								<ul class="xhSelect_list">
									<li class="xhSelect_item xhSelect_item_tips" data-value="">请选择</li>
					`;
					$.each(_InitData, function () {
						if (this.key == selectKey) {
							_html += `<li class="xhSelect_item xhSelect_item_selected" data-value="` + this.key + `">` + this.value + `</li>`;
						} else {
							_html += `<li class="xhSelect_item" data-value="` + this.key + `">` + this.value + `</li>`;
						}
					});
					_html += `
								</ul>
							</div>
						</div>
					`;

					// 获取下级初始化数据
					$.each(_InitData, function () {
						if (this.key == selectKey) {
							_InitData = this.children;
							return false;
						}
					});
				} else {
					_html += `
						<div class="xhLinkDrop_item" date-level="` + i + `">
							<div class="xhSelect">
								<p class="xhSelect_relt xhSelect_relt_unselect">
									<span data-key="">请选择</span>
									<i class="iconfont icon-row-bottom2"></i>
								</p>
								<ul class="xhSelect_list">
									<li class="xhSelect_item xhSelect_item_tips" data-value="">请选择</li>
					`;
					$.each(_InitData, function () {
						_html += `<li class="xhSelect_item" data-value="` + this.key + `">` + this.value + `</li>`;
					});
					_html += `
								</ul>
							</div>
						</div>
					`;

					_InitData = [];
				}

			}
			_html += `</div>`;
			$this.append(_html);

			// 设置结果显示元素宽度
			$this.find(".xhSelect").each(function() {
				let itemWidth = $(this).find(".xhSelect_list").width();
				if (itemWidth > $(this).width()) {
					$(this).css({
						width: itemWidth + "px"
					})
				}
			});

			// 展开/关闭下拉菜单事件
			$this.find(".xhSelect_relt").click(function () {
				// 关闭兄弟层级的下拉菜单
				let other = $(this).closest(".xhLinkDrop_item").siblings().find(".xhSelect");
				other.removeClass("xhSelect_open");
				other.find(".xhSelect_list").hide();

				let select = $(this).closest(".xhSelect");
				if (!select.hasClass("xhSelect_open")) {
					select.addClass("xhSelect_open");
					select.find(".xhSelect_list").show();
				} else {
					select.removeClass("xhSelect_open");
					select.find(".xhSelect_list").hide();
				}
			});

			// 点击选项事件
			$this.on("click", ".xhSelect_item", function () {
				if (!$(this).hasClass("xhSelect_item_selected")) {
					// 设置选项的选中样式
					$(this).siblings(".xhSelect_item_selected").removeClass("xhSelect_item_selected");
					if (!$(this).hasClass(".xhSelect_item_tips")) {
						$(this).addClass("xhSelect_item_selected");
					}

					// 设置选中值
					let result = $(this).closest(".xhSelect").find(".xhSelect_relt span");
					let selectKey = $(this).attr("data-value");
					let selectValue = $(this).html();
					result.attr("data-key", selectKey);
					result.html(selectValue);
					if (result.closest(".xhSelect_relt").hasClass("xhSelect_relt_unselect")) {
						if (selectKey != "") {
							result.closest(".xhSelect_relt").removeClass("xhSelect_relt_unselect");
						}
					} else {
						if (selectKey == "") {
							result.closest(".xhSelect_relt").addClass("xhSelect_relt_unselect");
						}
					}

					// 初始化后续层级下拉菜单
					let nextSelect = $(this).closest(".xhLinkDrop_item").nextAll();
					nextSelect.each(function () {
						$(this).find(".xhSelect_item").not(".xhSelect_item_tips").remove();
						$(this).find(".xhSelect_relt").addClass("xhSelect_relt_unselect");
						$(this).find(".xhSelect_relt span").html("请选择");
						$(this).find(".xhSelect_relt span").attr("data-key", "");
					});

					_InitData = opts.data;
					_Selected = [];
					for (var i = 0; i < opts.level; i++) {
						let select = $this.find(".xhSelect").eq(i);
						let thisKey = select.find(".xhSelect_relt span").attr("data-key");
						if (!$.xhLib.isEmpty(thisKey)) {
							let thisValue = select.find(".xhSelect_relt span").html();
							let thisSelected = {
								key: thisKey,
								value: thisValue
							};
							_Selected.push(thisSelected);

							// 获得下级选项列表
							$.each(_InitData, function () {
								if (this.key == thisKey) {
									_InitData = this.children;
								}
							})
						} else {
							console.log(i);

							// 追加本级选项列表
							let itemList = select.find(".xhSelect_list");
							$.each(_InitData, function () {
								let _itemHtml = `<li class="xhSelect_item" data-value="` + this.key + `">` + this.value + `</li>`;
								itemList.append(_itemHtml);
							});

							break;
						}
					}
				}

				// 关闭下拉菜单
				let select = $(this).closest(".xhSelect");
				select.removeClass("xhSelect_open");
				select.find(".xhSelect_list").hide();

				opts.complate(_Selected);
			});
		});
	};

	$.fn.xhLinkDrop.defaults = {
		data: [{ key: 1, value: "选项1", children: [{ key: 11, value: "子项1" }, {key:12, value: "子项2"}] }, { key: 2, value: "选项2" }],
		level: 2,
		selected: [],
		complate: function (i) { },
		err: function (e) { }
	};
})(jQuery);


// 步骤控制
jQuery.xhStep = function (selector, options) {
	let defaults = {
		width: 1000,
		color: '#2d8cf0',
		currNum: 1,
		currClick: function(i) { },
	};
	var opts = $.extend({}, defaults, options);

	// 获得操作对象
	var $this = $("#" + selector);

	//获得总步骤数量
	var _stepCount = $this.find('li').length;
	if (_stepCount > 0) {
		load(opts);
	}

	function load(opts) {
		$this.children("div").remove();
		//设置容器
		$this.css({ width: opts.width + 'px' });

		//设置进度条
		var _barBoxWidth = opts.width / _stepCount * (_stepCount - 1);
		var _barBoxSpan = opts.width / _stepCount / 2;
		var _barWidth = opts.width / _stepCount * (opts.currNum - 1);
		var _barColor = '';
		if (opts.color != '') {
			_barColor = 'background-color: ' + opts.color + ';'
		}
		$this.prepend('<div style="width:' + _barBoxWidth + 'px; left:' + _barBoxSpan + 'px; right:' + _barBoxSpan + 'px;"><p style="width:' + _barWidth + 'px; ' + _barColor +'"></p></div>');

		//设置步骤
		for (var i = 0; i < _stepCount; i++) {
			var _stepItem = $this.find('li').eq(i);
			var _text = _stepItem.find("span").length > 0 ? _stepItem.find("span").html() : _stepItem.html();
			if (i < opts.currNum) {
				var _newStep = '';
				if (opts.color != '') {
					_newStep = '<i style="background-color: ' + opts.color + '">' + (i + 1) + '</i><span style="color: ' + opts.color + '">' + _text + '</span>'
				} else {
					_newStep = '<i>' + (i + 1) + '</i><span>' + _text + '</span>'
				}
				_stepItem.replaceWith('<li class="curr">' + _newStep + '</li>');
			} else {
				var _newStep = '<i>' + (i + 1) + '</i><span>' + _text + '</span>';
				_stepItem.replaceWith('<li>' + _newStep + '</li>');
			}
		}

		//已完成步骤的Click事件
		$this.find('li.curr i').click(function () {
			var _i = $this.find('li.curr').index($(this).closest('li'));
			opts.currClick(_i);
		});
		$this.find('li.curr span').click(function () {
			var _i = $this.find('li.curr').index($(this).closest('li'));
			opts.currClick(_i);
		});
	}

	// 重载
	var reload = function (options) {
		var newOpts = $.extend({}, opts, options);
		load(newOpts);
	}

	return {
		reload: reload,
	}
};


// xhAutoTextarea自动高度
(function ($) {
	$.fn.xhAutoTextarea = function(options) {
		var defaults = {
			maxHeight: null,
			minHeight: $(this).height()
		};

		var opts = $.extend({},defaults, options);

		return $(this).each(function() {
			var height, style = this.style;
			this.style.height = opts.minHeight + 'px';
			if (this.scrollHeight > opts.minHeight) {
				if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
					height = opts.maxHeight;
					style.overflowY = 'scroll';
				} else {
					height = this.scrollHeight;
					style.overflowY = 'hidden';
				}
				style.height = height + 'px';
			}

			$(this).bind("input",
			function() {
				var height, style = this.style;
				this.style.height = opts.minHeight + 'px';
				if (this.scrollHeight > opts.minHeight) {
					if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
						height = opts.maxHeight;
						style.overflowY = 'scroll';
					} else {
						height = this.scrollHeight;
						style.overflowY = 'hidden';
					}
					style.height = height + 'px';
				}
			});
		});
	};
})(jQuery);

// xhTimeAxis时间轴
var xhTimeAxis = function (selector, options) {
	// 根据ID获得对象
	var get_dom = function (jqDom) {
		return $("#" + jqDom);
	}

	// 获得操作对象
	var obj = get_dom(selector);

	// 时间轴明细处理方法
	var handle = function () {
		obj.find(".xhTimeAxis_item").not("[data-handled=1]").each(function () {
			$(this).attr("data-handled", "1");
			$(this).prepend('<i class="xhTimeAxis_icon iconfont icon-danxuan_weixuanzhong"></i>');
		});
	}

	// 执行时间轴处理程序
	handle();

	// 追加元素处理事件
	var re_handle = function () {
		handle();
	}

	return {
		reHandle: re_handle,
	}
};

// xhDrawer抽屉
var xhDrawer = function (selector, options) {
	// 根据ID获得对象
	var get_dom = function (jqDom) {
		return $("#" + jqDom);
	}

	// 获得参数
	var opts = options || {};
	opts.width = $.xhLib.toInt(opts.width, 400);						// 抽屉宽度
	if (opts.showClose !== true && opts.showClose !== false) {
		opts.showClose = true;
	}
	if ($.xhLib.isEmpty(opts.title)) {
		opts.title = "抽屉标题"
	}

	// 获得操作对象
	var obj = get_dom(selector);

	// 初始化抽屉
	var init = function () {
		obj.css({ width: '0px' });
		obj.find(".xhDrawerBrace").css({ width: opts.width + 'px' });

		let closeHtml = '';
		if (opts.showClose) {
			closeHtml = '<a href="javascript:void(0)" class="xhDrawerClose">×</a>';
		}
		let html = `
			<div class="xhDrawerTitle">
				<span>` + opts.title + `</span>
				` + closeHtml + `
            </div>
		`;
		obj.find(".xhDrawerBrace").append(html);

	}
	init();

	obj.on("click", ".xhDrawerClose", function () {
		obj.animate({width: '0px'});
	})

	// 打开抽屉
	var open = function () {
		obj.animate({ width: opts.width + 'px' });
	}

	// 关闭抽屉
	var close = function () {
		obj.animate({width: '0px'});
	}

	return {
		open: open,
		close: close,
	}
};


// xhUppic上传（单图）
var xhUppic = function (selector, options) {
	// 根据ID获得对象
	var get_dom = function (jqDom) {
		return $("#" + jqDom);
	};

	var $this = get_dom(selector);

	// 接收参数
	var defaults = {
		ext: 'jpg,jpeg,png',
		prefix: 'Upload',
		domain: '',
		upUrl: '',
		toOss: false,
		ossParamUrl: '',
		submit: '<i class="iconfont icon-tupian" style="font-size:24px; color:#999999;"></i>',
		size: "5MB",
		pic: '',
		complete: function (pic) { },
	};

	var opts = $.extend({}, defaults, options);

	// 初始化图片列表
	var picInit = function (pic) {
		let picHtml = '';
		if (pic && pic != '') {
			picHtml = '<img alt="" src="' + $.xhLocal.getFilePath(pic, opts.prefix, opts.domain) + '" />';
		} else {
			picHtml = opts.submit;
		}
		return picHtml
	};

	// 构造
	let _html = '<a href="javascript:void(0)" class="xhUppic">' + picInit(opts.pic) + '</a>';
	$this.append(_html);

	// 上传控件初始化
	let _href = $this.find("a")[0];
	let xhUpload = new plupload.Uploader({
		browse_button: _href,
		runtimes: 'html5,html4',
		chunk_size: opts.size,
		multi_selection: false,
		url: opts.upUrl,
		filters: { max_file_size: opts.size, mime_types: [{ title: '图片文件', extensions: opts.ext }] },
		init: {
			PostInit: function () {
			}, 
			// 文件添加到上传队列
			FilesAdded: function (up, files) {
				up.start();
			}, 
			// 上传前
			BeforeUpload: function (up, file) {
				$.xhLocal.setUploadParam(up, file, opts.prefix, opts.toOss, opts.ossParamUrl);
			}, 
			// 上传进度
			UploadProgress: function (up, file) { }, 
			// 单个上传完毕
			FileUploaded: function (up, file) {
				let _picName = file.id + file.name.substring(file.name.lastIndexOf('.'), file.name.length);
				let _picPath = $.xhLocal.getFilePath(_picName, opts.prefix, opts.domain);
				opts.pic = _picName;
				$this.find("a").html('<img alt="" src="' + _picPath + '" />');
			}, 
			// 全部上传完毕
			UploadComplete: function (up, files) {
				opts.complete(opts.pic);
			}, 
			// 错误信息
			Error: function (up, err) {
				if (err.code == -600) {
					$.xhToast({
						msg: '选择的文件太大了'
					});
				}
				else if (err.code == -601) {
					$.xhToast({
						msg: '选择的文件后缀不对'
					});
				}
				else if (err.code == -602) {
					$.xhToast({
						msg: '这个文件已经上传过一遍了'
					});
				}
				else {
					$.xhToast({
						msg: 'Error xml:' + err.response
					});
				}
			}
		}
	});
	xhUpload.init();

	// 重置图片列表
	var ResetPics = function (pic) {
		if (!pic) { pic = ''; }
		$this.find("a").html(picInit(pic));
		opts.pic = pic;
	};

	return {
		ResetPics: ResetPics,
	}
};

// xhUppics上传（多图）
var xhUppics = function (selector, options) {
	// 根据ID获得对象
	var get_dom = function (jqDom) {
		return $("#" + jqDom);
	};

	var $this = get_dom(selector);

	// 接收参数
	var defaults = {
		ext: 'jpg,jpeg,png',
		prefix: "Upload",
		domain: "",
		upUrl: "",
		toOss: false,
		ossParamUrl: "",
		count: 3,
		size: "5MB",
		pics: [],
		complete: function (pics) { },
	};

	var opts = $.extend({}, defaults, options);

	// 初始化图片列表
	var picsInit = function (pics) {
		let picHtml = '';
		if (pics) {
			$.each(pics, function () {
				picHtml += '<li class="xhUppicsPic"><img alt="" src="' + $.xhLocal.getFilePath(this, opts.prefix, opts.domain) + '" /><a href="javascript:void(0)"><i class="iconfont icon-guanbi"></i></a></li>';
			});
		}
		return picHtml
	};

	// 构造
	let hrefHtml = '<li class="xhUppicsHref"><a href="javascript:void(0)"><i class="iconfont icon-tupian"></i></a></li>';
	let _html = '<ul class="xhUppics">' + picsInit(opts.pics) + hrefHtml + '</ul>';
	$this.append(_html);

	// 上传控件初始化
	let _href = $this.find(".xhUppicsHref a")[0];
	let xhUpload = new plupload.Uploader({
		browse_button: _href,
		runtimes: 'html5,html4',
		chunk_size: opts.size,
		multi_selection: true,
		url: opts.upUrl,
		filters: { max_file_size: opts.size, mime_types: [{ title: '图片文件', extensions: opts.ext }] },
		init: {
			PostInit: function () {
				// 判断是否显示按钮
				if (opts.pics.length >= opts.count) {
					$this.find(".xhUppicsHref").hide();
				}
			},
			// 文件添加到上传队列
			FilesAdded: function (up, files) {
				if (opts.pics.length + files.length > opts.count) {
					$.each(files, function () {
						up.removeFile(this);
					});

					$.xhToast({
						msg: '最多只能上传' + opts.count + '个图片'
					});
				} else {
					if (opts.pics.length + files.length == opts.count) {
						$this.find(".xhUppicsHref").hide();
					}
					up.start();
				}
			},
			// 上传前
			BeforeUpload: function (up, file) {
				$.xhLocal.setUploadParam(up, file, opts.prefix, opts.toOss, opts.ossParamUrl);
			},
			// 上传进度
			UploadProgress: function (up, file) { },
			// 单个上传完毕
			FileUploaded: function (up, file) {
				let _picName = file.id + file.name.substring(file.name.lastIndexOf('.'), file.name.length);
				let _picPath = $.xhLocal.getFilePath(_picName, opts.prefix, opts.domain);
				// 数组中追加元素
				opts.pics.push(_picName);
				// HTML中追加元素
				let _picHtml = '<li class="xhUppicsPic"><img alt="" src="' + _picPath + '" /><a href="javascript:void(0)"><i class="iconfont icon-guanbi"></i></a></li>';
				$this.find(".xhUppicsHref").before(_picHtml);
			},
			// 全部上传完毕
			UploadComplete: function (up, files) {
				opts.complete(opts.pics);
			},
			// 错误信息
			Error: function (up, err) {
				if (err.code == -600) {
					$.xhToast({
						msg: '选择的文件太大了'
					});
				}
				else if (err.code == -601) {
					$.xhToast({
						msg: '选择的文件后缀不对'
					});
				}
				else if (err.code == -602) {
					$.xhToast({
						msg: '这个文件已经上传过一遍了'
					});
				}
				else {
					$.xhToast({
						msg: 'Error xml:' + err.response
					});
				}
			}
		}
	});
	xhUpload.init();

	// 删除图片
	$this.on("click", ".xhUppicsPic a", function () {
		let _box = $(this).closest(".xhUppicsPic");
		let _i = _box.index();							// 获得索引

		_box.remove();
		opts.pics.splice(_i, 1);

		if ($this.find(".xhUppicsPic").length < opts.count) {
			$this.find(".xhUppicsHref").show();
		}

		opts.complete(opts.pics);
	});

	// 重置图片列表
	var ResetPics = function (pics) {
		if (!pics) { pics = []; }
		$this.find(".xhUppicsPic").remove();
		let _picHtml = picsInit(pics);
		$this.find(".xhUppicsHref").before(_picHtml);
		opts.pics = pics;
	};

	return {
		ResetPics: ResetPics,
	}
};

// 文件上传
var xhUpfiles = function (selector, options) {
	// 根据ID获得对象
	var get_dom = function (jqDom) {
		return $("#" + jqDom);
	};

	var $this = get_dom(selector);

	// 接收参数
	var defaults = {
		ext: 'doc,docx,xls,xlsx,ppt,pptx,pdf,txt,rar,zip,mp4',		// 上传文件类型
		prefix: "Files",											// 上传到文件夹
		count: 3,													// 限制上传数量
		size: "5MB",												// 文件大小限制
		toOss: false,												// 是否上传到阿里云OSS
		upUrl: "",													// 本地上传API接口
		ossDomain: "",												// 阿里云OSS域名
		ossParamUrl: "",											// 获得阿里云OSS上传参数接口
		files: [],													// 初始文件记录
		complete: function (files) { },								// 上传完成事件
	};

	var opts = $.extend({}, defaults, options);

	let chunk_size = opts.toOss ? opts.size : "5MB";

	// 初始化文件列表
	var filesInit = function (_files) {
		let fileHtml = '';
		if (_files) {
			$.each(_files, function () {
				let _html = `
							<div class="xhUpfileItem" data-name="` + this.db_name + `">
								<div>
									<span>[` + this.size + `]&nbsp;&nbsp;` + this.file_name + `</span>
									<a href="javascript:void(0)" data-status="1">删除</a>
								</div>
								<p><label style="width:100%"></label></p>
							</div>
							`;
				fileHtml += _html;
			});
		}
		return fileHtml
	};

	// 构造
	let failHtml = '<div class="xhUpfileInitFail">您的浏览器不支持HTML5上传方式</div>';
	let hrefHtml = '<a href="javascript:void(0);" class="xhUpfileBtn">选择并上传文件</a>';
	let _html = '<div class="xhUpfile">' + filesInit(opts.files) + hrefHtml + failHtml + '</div>';
	$this.append(_html);

	// 上传控件初始化
	let _href = $this.find(".xhUpfileBtn")[0];
	let xhUpload = new plupload.Uploader({
		browse_button: _href,
		runtimes: 'html5',
		chunk_size: chunk_size,
		multi_selection: true,
		url: opts.upUrl,
		filters: { max_file_size: opts.size, mime_types: [{ title: '上传文件', extensions: opts.ext }] },
		init: {
			PostInit: function () {
				$this.find(".xhUpfileInitFail").hide();
				// 判断是否显示按钮
				if (opts.files.length >= opts.count) {
					$this.find(".xhUpfileBtn").hide();
				}
			},
			// 文件添加到上传队列
			FilesAdded: function (up, files) {
				if (opts.files.length + files.length > opts.count) {
					$.each(files, function () {
						up.removeFile(this);
					});

					$.xhToast({
						msg: '最多只能上传' + opts.count + '个文件'
					});
				} else {
					plupload.each(files, function (file) {
						let _html = `
									<div class="xhUpfileItem" id="` + file.id + `">
										<div>
											<span>[` + plupload.formatSize(file.size) + `]&nbsp;&nbsp;` + file.name + `</span>
											<a href="javascript:void(0)" data-status="0">0%</a>
										</div>
										<p><label style="width:0%"></label></p>
									</div>
									`;
						$this.find(".xhUpfileBtn").before(_html);
					});

					if (opts.files.length + files.length == opts.count) {
						$this.find(".xhUpfileBtn").hide();
					}
					up.start();
				}
			},
			// 上传前
			BeforeUpload: function (up, file) {
				$.xhLocal.setUploadParam(up, file, opts.prefix, opts.toOss, opts.ossParamUrl);
			},
			// 上传进度
			UploadProgress: function (up, file) {
				var d = $this.find('#' + file.id);
                d.find("label").css("width", file.percent + "%");
                d.find("a").html(file.percent + "%");
			},
			// 单个上传完毕
			FileUploaded: function (up, file) {
				var _db_name = file.id + file.name.substring(file.name.lastIndexOf("."), file.name.length);
				let _html = `
							<div class="xhUpfileItem" data-name="` + _db_name + `">
								<div>
									<span>[` + plupload.formatSize(file.size) + `]&nbsp;&nbsp;` + file.name + `</span>
									<a href="javascript:void(0)" data-status="1">删除</a>
								</div>
								<p><label style="width:100%"></label></p>
							</div>
							`;
				var d = $this.find('#' + file.id);
				d.replaceWith(_html);

				// 数组中追加元素
				opts.files.push({
					"db_name": _db_name,
					"size": plupload.formatSize(file.size),
					"file_name": file.name
				});
			},
			// 全部上传完毕
			UploadComplete: function (up, files) {
				opts.complete(opts.files);
			},
			// 错误信息
			Error: function (up, err) {
				if (err.code == -600) {
					$.xhToast({
						msg: '选择的文件太大了'
					});
				}
				else if (err.code == -601) {
					$.xhToast({
						msg: '选择的文件后缀不对'
					});
				}
				else if (err.code == -602) {
					$.xhToast({
						msg: '这个文件已经上传过一遍了'
					});
				}
				else {
					$.xhToast({
						msg: 'Error xml:' + err.response
					});
				}
			}
		}
	});
	xhUpload.init();

	// 删除文件
	$this.on("click", ".xhUpfileItem a", function () {
		if ($(this).data("status") == 1) {
			let _box = $(this).closest(".xhUpfileItem");
			let _i = _box.index();							// 获得索引

			_box.remove();
			opts.files.splice(_i, 1);

			if ($this.find(".xhUpfileItem").length < opts.count) {
				$this.find(".xhUpfileBtn").show();
			}

			opts.complete(opts.files);
		}
	});
};

// xhScrollBottom滚动到底部事件
var xhScrollBottom = function (selector, options) {
	// 根据ID获得对象
	var get_dom = function (jqDom) {
		if (jqDom == "body") {
			return $(document);
		} else {
			return $("#" + jqDom);
		}
	};

	var $this = get_dom(selector);

	// 接收参数
	var defaults = {
		minAwayBtm: 50,
		func: function (pic) { },
	};

	var opts = $.extend({}, defaults, options);

	let implement = true;

	$this.scroll(function () {
		let maxHeight = $this.height();
		let awayBtm = $this.height() - $this.scrollTop() - $this.parent().height();
		if (awayBtm <= opts.minAwayBtm) {
			if (implement) {
				implement = false;
				opts.func();
		console.log("我执行了")
				implement = true;
			}
        }
	});

	// 重置图片列表
	var Close = function () {
		implement = false;
		console.log("我关闭了")
	};

	return {
		Close: Close,
	}
};

// xhProgress进度条
(function ($) {
	$.fn.xhProgress = function(options) {
		var defaults = {
			init: 0,
			complate: function (s) { }
		};

		var opts = $.extend({}, defaults, options);

		this.each(function () {
			var $this = $(this);

			let _html = `
				<div class="xhProgress">
					<div style="width:` + opts.init + `%"></div>
					<p>` + opts.init + `</p>
					<a href="javascript:void(0)" style="left: ` + opts.init + `%"></a>
				</div>
			`;
			$this.html(_html);

			$this.find("a").mouseover(function () {
				$this.find("p").show();
			});

			$this.find("a").mouseout(function () {
				$this.find("p").hide();
			});

			// 拖拽效果
			let _offset = 0;		//鼠标拖动按钮时，鼠标距离圆心的偏移量

			$this.find("a").mousedown(function (event) {
				_offset = event.clientX - $this.offset().left - $this.width() * opts.init / 100;
				// deltay = event.clientY - $this.offset().top;
				$(document).bind('mousemove', start)
				$(document).bind('mouseup', end)
				return false;
			});

			function start(event) {
				opts.init = parseInt((event.clientX - $this.offset().left - _offset) / $this.width() * 100);

				if (opts.init < 0) {
					opts.init = 0;
				} else if (opts.init > 100) {
					opts.init = 100;
				}

				$this.find("a").css({ left: opts.init + "%" });
				$this.find(".xhProgress div").css({ width: opts.init + "%" });
				$this.find("p").css({ left: opts.init + "%" });
				$this.find("p").html(opts.init);

				return false;
			}

			function end() {
				opts.complate(opts.init);
				$(document).unbind('mousemove')
				$(document).unbind('mouseup')
			}

			// 单击进度条
			$this.find(".xhProgress").click(function (event) {
				opts.init = parseInt((event.clientX - $this.offset().left) / $this.width() * 100);

				if (opts.init < 0) {
					opts.init = 0;
				} else if (opts.init > 100) {
					opts.init = 100;
				}

				$this.find("a").css({ left: opts.init + "%" });
				$this.find(".xhProgress div").css({ width: opts.init + "%" });
				$this.find("p").css({ left: opts.init + "%" });
				$this.find("p").html(opts.init);

				opts.complate(opts.init);
				return false;
			});
		});
	};
})(jQuery);

// xhWangEditor富文本编辑器
(function ($) {
	$.fn.xhWangEditor = function(options) {
		var opts = $.extend({}, $.fn.xhWangEditor.defaults, options);

		const { createEditor, createToolbar } = window.wangEditor;

		let i = 0;
		this.each(function () {
			var $this = $(this);

			// 生成html结构
			let _html = `
				<div class="xhweWarp" id="xhweWarp_` + i + `">
					<div class="xhweToolbar" id="xhweToolbar_` + i + `"><!-- 工具栏 --></div>
					<div class="xhweEditor" id="xhweEditor_` + i + `"><!-- 编辑器 --></div>
				</div>
			`;
			$this.append(_html);

			// 配置编辑器
			const editorConfig = {
				placeholder: opts.placeholder,
				onChange(editor) {
					opts.html = editor.getHtml()
					opts.textChange(opts.html);
				},
				MENU_CONF: {}			//初始化 MENU_CONF 属性
			}

			if (opts.picToOss) {
				// 上传到阿里云服务器
				editorConfig.MENU_CONF['uploadImage'] = {
					async customUpload(file, insertFn) {
						let params = await $.getJSON(opts.ossParamUrl + '?t=' + Math.random(), function (data, status) {
							if (status == "success") {
								if (data.RespHead.Code == "0000") {
									return data.RespBody;
								} else {
									console.log(data);
									return false;
								}
							} else {
								console.log(data);
								return false;
							}
						});

						if (params) {
							// 获得文件后缀
							let _pos = file.name.lastIndexOf('.')
							let _suffix = file.name.substring(_pos);
							// 获得文件名
							let _fileName = $.xhLocal.getFileName(_suffix);
							// 获得Oss文件名
							let _objectName = $.xhLocal.getFilePath(_fileName, "Upload", "");
							_objectName = _objectName.substr(1 - _objectName.length);

							const formData = new FormData()
							formData.append('OSSAccessKeyId', params.accessid)
							formData.append('policy', params.policy)
							formData.append('signature', params.signature)
							formData.append('key', _objectName)
							formData.append('file', file)
							formData.append('host', params.host)

							$.ajax({
								url: params.host,
								data: formData,
								type: "POST",
								dataType: "json",
								async: false,
								contentType: false,
								processData: false,
								success: function (rsp) {
									insertFn(params.host + '/' + _objectName, "", "")
								},
								error: function (e) {
									console.log(e);
									$.xhToast({
										msg: "上传文件到阿里云OSS失败"
									});
								}
							});
						} else {
							$.xhToast({
								msg: "获取阿里云上传参数失败"
							});
						};
					},

				}
			} else {
				// 上传到本地服务器
				editorConfig.MENU_CONF['uploadImage'] = {
					server: opts.localServUrl,
					meta: opts.localServParam,
				}
			}

			const editor = createEditor({
				selector: "#xhweEditor_" + i,
				html: opts.html,
				config: editorConfig,
				mode: 'default', // or 'simple'
			})

			// 配置工具栏
			const toolbarConfig = {}
			const toolbar = createToolbar({
				editor,
				selector: '#xhweToolbar_' + i,
				config: toolbarConfig,
				mode: 'simple', // or 'simple'
			})

			i += 1;
		});
	};

	$.fn.xhWangEditor.defaults = {
		placeholder: "",							// 为空时候的占位符
		html: "",									// 初始时绑定的html内容
		picToOss: false,							// 图片是否上传到OSS
		localServUrl: "",							// 本地上传服务器地址
		localServParam: {},							// 本地上传服务器参数
		ossParamUrl: "",							// 获得OSS上传参数地址
		textChange: function (html) { },			// 内容改变时的事件
	};
})(jQuery);


// xhScaling等比缩放
(function ($) {
	$.fn.xhScaling = function (options) {
		var opts = $.extend({}, $.fn.scaleZoom.defaults, options);

		this.each(function () {
			var _this = $(this);
			if (opts.byType == 'w2h') {
				_this.css({ height: (_this.width() / opts.scale) + 'px' });
			} else if (opts.byType == 'h2w') {
				_this.css({ width: (_this.height() * opts.scale) + 'px' });
			} else {
				console.log('options.byType = width / height');
			}
		});
	};

	$.fn.xhScaling.defaults = {
		byType: 'w2h',
		scale: 3 / 2
	};
})(jQuery);


// Laytable封装
var xhLaytable = function (options) {
	// 默认参数
	var defaults = {
		tableElem: "LayuiTable",
		tableTools: "",
		tableCols: [[
			{ title: '选择', width: 50, type: 'checkbox', align: 'center' },
			{ field: 'RowIndex', title: '序号', width: 80, align: 'center' },
			{ field: 'Id', title: 'ID', width: 80, align: 'center' },
			{
				field: 'CreateTime', title: '创建时间', width: 180, align: 'center', templet: function (item) {
					return moment.unix(item.CreateTime).format("YYYY-MM-DD HH:mm:ss");
				}
			},
			{
				title: '删除', width: 80, fixed: 'right', align: 'center', templet: function (item) {
					return '<a href="javascript:void(0)" class="clR" lay-event="RowDelt">[删除]</a>';
				}
			},
			{
				title: '编辑', width: 80, fixed: 'right', align: 'center', templet: function (item) {
					return '<a href="javascript:void(0)" class="clB" lay-event="RowEdit">[编辑]</a>';
				}
			},
		]],
		tableData: [],
		tableEvent: function (o, t) {
			console.log(o.event);
		},
		rowEvent: function (o, t) {
			console.log(o.event);
		},
		colsEdit: function (o, t) {
			console.log(oo.field);
		},
		pageElem: "LayuiPage",
		totalCount: 0,
		pageSize: 20,
		currPage: 1
	};

	// 获得参数
	var opts = $.extend({},defaults, options);

	// 构建LayuiTable
	layui.use(['table', 'laypage'], function () {
		var table = layui.table;
		var laypage = layui.laypage;

		// 配置表格
		table.render({
			elem: '#' + opts.tableElem,
			toolbar: opts.tableTools != "" ? "#" + opts.tableTools : false,
			defaultToolbar: false,
			autoSort: false,
			limit: Number.MAX_VALUE,
			size: "sm",
			cols: opts.tableCols,
			data: opts.tableData
		});

		// 监听头部工具
		table.on('toolbar(' + opts.tableElem + ')', function (obj) {
			opts.tableEvent(obj, table);
		});

		// 单元格工具
		table.on('tool(' + opts.tableElem + ')', function (obj) {
			opts.rowEvent(obj, table);
		});

		// 单元格编辑
		table.on('edit(' + opts.tableElem + ')', function(obj){ 
			opts.colsEdit(obj, table);
		});

		// 加载分页
		if (opts.pageElem != "") {
			laypage.render({
				elem: opts.pageElem,
				theme: '#2d8cf0',
				count: opts.totalCount,
				limit: opts.pageSize,
				curr: opts.currPage,
				layout: ['prev', 'page', 'next', 'skip'],
				jump: function (obj, first) {
					if (!first) {
						let href = window.location.href;
						let parts = [];

						if (href.indexOf("?") >= 0) {
							let querys = href.substring(href.indexOf("?") + 1);
							if (querys != "") {
								let qary = querys.split("&");
								for (var i = 0; i < qary.length; i++) {
									let q = qary[i];
									if (q.substring(0, 5) == "page=") {
										parts.push("page=" + obj.curr);
									} else {
										parts.push(q);
									}
								}
							}
						}

						if (!parts.includes("page=" + obj.curr)) {
						  parts.push("page=" + obj.curr);
						}

						href = href.split("?")[0] + "?" + parts.join("&");

						window.location.href = href;
					}
				}
			});
		}
	});
};

// 自定义鼠标右键菜单
(function ($) {
	$.fn.mouseRightMenu = function (options) {
		var opts = $.extend({}, $.fn.mouseRightMenu.defaults, options);

		this.each(function () {
			var $this = $(this);

			$this.mousedown(function (e) {
				$('#xh_mouseRightMenu').remove();
				if (e.button == 2) {
					var _x = e.pageX - 2;
					var _y = e.pageY - 2;

					var _html = '<section id="xh_mouseRightMenu" style="left:' + _x + 'px; top:' + _y + 'px">';
					_html += '<ul>';
					if (opts.menus.length > 0) {
						for (var i = 0; i < opts.menus.length; i++) {
							var menu = opts.menus[i];
							_html += '<li><a href="javascript:void(0)" xh-event="' + menu.event + '"><i class="iconfont ' + menu.icon + '"></i>' + menu.text + '</a></li>';
						}
					}
					_html += '</ul>';
					_html += '</section>';

					$('body').append(_html);
				}

				//移出弹窗
				$('#xh_mouseRightMenu').mouseleave(function () {
					$('#xh_mouseRightMenu').remove();
				});

				//点击按钮
				$('#xh_mouseRightMenu a').click(function () {
					var _event = $(this).attr('xh-event');
					opts.menuClick($this, _event);
					$('#xh_mouseRightMenu').remove();
				});
			})
		});
	}

	$.fn.mouseRightMenu.defaults = {
		menus: [
			{ icon: 'icon-edit', text: '编辑', event: 'edit' },
			{ icon: 'icon-delete', text: '删除', event: 'delete' }
		],
		menuClick: function (o, e) {
			console.log(e);
		},
	};
})(jQuery);
